﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Utils;

namespace Logic
{
    public class Alumnos : Personas
    {
        private Data.Alumnos _hnd_alumnos = new Data.Alumnos();
        private Data.Planes _hnd_planes = new Data.Planes();

        private Data.Alumnos HndAlumnos
        {
            get { return _hnd_alumnos; }
        }
        private Data.Planes HndPlanes
        {
            get { return _hnd_planes; }
        }

        public Entities.Alumno GetByLegajo(int legajo)
        {
            return HndAlumnos.GetByLegajo(legajo);
        }

        public Entities.Collections.AlumnosCollection GetByPlan(Entities.Plan plan)
        {
            return HndAlumnos.GetByPlan(plan);
        }

        public Entities.Collections.AlumnosCollection GetCollection()
        {
            return HndAlumnos.GetCollection();
        }

        private string Validate(Entities.Alumno instance)
        {
            StringBuilder b = base.Validate(instance);

            if (HndPlanes.GetByID(instance.IDPlan) == null) b.AppendLine("* El alumno no tiene un plan asociado");

            return b.ToString();
        }

        public string Save(Entities.Alumno instance)
        {
            string r = Validate(instance);

            if (r.IsEmptyString())
            {
                instance.Nombre = instance.Nombre.Trim();
                instance.Apellido = instance.Apellido.Trim();
                instance.Direccion = instance.Direccion.Trim();
                instance.Telefono = instance.Telefono.Trim();
                instance.Email = instance.Email.Trim();
                HndAlumnos.Save(instance);
            }

            return r;
        }
    }
}
